package com.dtw.ditouwang.ui.mine;

import android.app.AlertDialog;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.dtw.ditouwang.BuildConfig;
import com.dtw.ditouwang.R;
import com.dtw.ditouwang.ui.BaseActivity;

public class AboutActivity extends BaseActivity implements View.OnClickListener {
    /**
     * “低头网”   咔嚓，咔嚓，奔跑，奔跑！
     * “低头网”  是一个合理规划时间、优化碎片生活的跃动平台。让我们一起来欣赏、创造这多姿多彩的美丽新时代！...详情
     */
    private TextView textAbout;
    /**
     * 赏个好评
     */
    private TextView textStore;
    private TextView textNum;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activty_about);
        initView();
        enableBack();
        setTitle("关于");
    }

    private void initView() {
        textAbout = findViewById(R.id.text_about);
        textAbout.setOnClickListener(this);
        textStore = findViewById(R.id.text_store);
        textStore.setOnClickListener(this);
        textNum = findViewById(R.id.text_num);
        textNum.setText("V "+BuildConfig.VERSION_NAME);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.text_about:
                View view = LayoutInflater.from(this).inflate(R.layout.dialog_about, null);
                final AlertDialog alertDialog = new AlertDialog.Builder(this).setView(view).show();
                Button confirm = view.findViewById(R.id.text_confirm);
                confirm.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        alertDialog.dismiss();
                    }
                });
                break;
            case R.id.text_store:
                try {
                    Uri uri = Uri.parse("market://details?id=" + getPackageName());
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }catch (Exception e){
                    showToast("没有找到对应的应用市场");
                }
                break;
        }
    }
}
